package org.procat.porrapp;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditarApostaActivity extends Activity {
	String codiPorra; 
	
	public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.editar_aposta);
        
        codiPorra = getIntent().getStringExtra("porra");
        
        Button btnAcceptarAposta = (Button)findViewById(R.id.btnAcceptar);
        btnAcceptarAposta.setOnClickListener(new View.OnClickListener() 
        {
	        public void onClick(View v)
	        {
	        	EditText txtApostant = (EditText) findViewById(R.id.txtApostant);
	        	EditText txtAposta = (EditText) findViewById(R.id.txtAposta);
	        	
	        	SharedPreferences prefs = getSharedPreferences("PorraData", 0);
	        	SharedPreferences.Editor editor = prefs.edit();
	        	
	        	int codiAposta = 1;
	        	
	        	for (; prefs.contains("Porra" + codiPorra + ".Aposta" + codiAposta + ".apostant")  ; codiAposta++);
	        	
	        	editor.putString("Porra" + codiPorra + ".Aposta" + codiAposta + ".apostant", txtApostant.getText().toString());
	        	editor.putString("Porra" + codiPorra + ".Aposta" + codiAposta + ".aposta", txtAposta.getText().toString());
	        	
	        	editor.commit();
	        	
	        	finish();
	        }
        });
    }
}
